﻿//-----------------------------------------------------------------------
// <copyright file="CharacterHelper.cs" company="FastNET Services">
//     Copyright (c) 2008-2009. All Rights Reserved.
// </copyright>
// <license>
//     GPLv2
// </license>
// <warranty>
//     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
//     BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
//     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
//     DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// </warranty>
//-----------------------------------------------------------------------
#region Usings

using System;
using GateShift.Common.Repository;
using GateShift.Common.Repository.Interfaces.DataInterfaces;
using GateShift.Common.Repository.Interfaces.Repositories;
using GateShift.Services.GameData.Entities;

#endregion

namespace GateShift.Testing.Services.GameData.Helpers
{
    /// <summary>
    /// Static Unit Test Helper Class for Character Entities
    /// </summary>
    internal static class CharacterHelper
    {
        /// <summary>
        /// Creates a completely random and unique character name
        /// </summary>
        /// <returns></returns>
        public static string CreateRandomCharacterName()
        {
            return Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 20);
        }

        /// <summary>
        /// Creates a character ready to save to the database
        /// </summary>
        /// <returns>ICharacterData with unique default values</returns>
        public static ICharacterData CreateCharacter()
        {
            return CreateCharacter(AccountHelper.CreateDBAccount().ID, RaceHelper.CreateDBRace().ID);
        }

        /// <summary>
        /// Creates a character ready to save to the database
        /// </summary>
        /// <param name="accountID">AccountID to associate the character with</param>
        /// <param name="raceID">RaceID to associate the character with</param>
        /// <returns>ICharacterData with unique default values</returns>
        public static ICharacterData CreateCharacter(Identity accountID, Identity raceID)
        {
            Character character = new Character();
            Random rnd = new Random();

            character.CharacterName = CreateRandomCharacterName();

            // Relations
            character.RaceID = (short)raceID;
            character.AccountID = (Guid)accountID;

            // Random bank account
            character.Money = rnd.Next(0, 100000);

            // Random ability modifiers
            character.BaseAccuracy = (byte)rnd.Next(0, 255);
            character.BaseAgility = (byte)rnd.Next(0, 255);
            character.BaseEndurance = (byte)rnd.Next(0, 255);
            character.BaseEnergy = (byte)rnd.Next(0, 255);
            character.BaseForce = (byte)rnd.Next(0, 255);
            character.BaseInsight = (byte)rnd.Next(0, 255);
            character.BaseIntellect = (byte)rnd.Next(0, 255);
            character.BaseStrength = (byte)rnd.Next(0, 255);
            character.BaseWill = (byte)rnd.Next(0, 255);

            return character;
        }

        /// <summary>
        /// Creates a character ready pre-saved to the database
        /// </summary>
        /// <returns>ICharacterData with unique default values</returns>
        public static ICharacterData CreateDBCharacter()
        {
            return CreateDBCharacter(AccountHelper.CreateDBAccount().ID, RaceHelper.CreateDBRace().ID);
        }

        /// <summary>
        /// Creates a character ready pre-saved to the database
        /// </summary>
        /// <param name="accountID">AccountID to associate the character with</param>
        /// <param name="raceID">RaceID to associate the character with</param>
        /// <returns>ICharacterData with unique default values</returns>
        public static ICharacterData CreateDBCharacter(Identity accountID, Identity raceID)
        {
            Character character = (Character)CreateCharacter(accountID, raceID);

            DBHelper.Provider.GetRepository<ICharacterRepository>().Save(character);

            return character;
        }
    }
}